package com.example.webapp.service.impl;

import com.example.webapp.bean.Registration;
import com.example.webapp.dao.RegistrationDao;
import com.example.webapp.service.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegistrationServiceImpl implements RegistrationService {
    private final RegistrationDao registrationDao;

    @Autowired
    public RegistrationServiceImpl(RegistrationDao registrationDao) {
        this.registrationDao = registrationDao;
    }

    @Override
    public void createRegistration(Registration registration) {
        registrationDao.save(registration);
    }

    @Override
    public void updateRegistration(Registration registration) {
        registrationDao.save(registration);
    }

    @Override
    public void deleteRegistration(Integer id) {
        registrationDao.deleteById(id);
    }

    @Override
    public List<Registration> getAllRegistrations() {
        return registrationDao.findAll();
    }

    @Override
    public Registration getRegistrationById(Integer id) {
        return registrationDao.findById(id).orElse(null);
    }

    @Override
    public List<Registration> findRegistrationsByStudent_Id(Integer uid) {
        return registrationDao.findRegistrationsByStudent_Id(uid);
    }
}

